/**
 * @class   wosh::xtended::Metronome
 * @brief   
 *
 *
 *
 ****************************************************************************
 * @version 0.8.161 $Id: Metronome.h 2574 2010-05-27 09:04:30Z alex $
 * @author  Alessandro Polo
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/

#ifndef __WOSH_Xtended_Metronome_H__
 #define __WOSH_Xtended_Metronome_H__

 #include <core/Thread.h>
 #include <core/Mutex.h>
 #include <core/Reflection.h>


namespace wosh {
 namespace xtended {

class IMetronomeListener;
 
///@todo synch/review vs. Timer.h

#define _Metronome_VERSION		0.12


class Metronome :	private wosh::ThreadImpl,
					public virtual wosh::IReflection
 {
	WOSH_CLASSNAME(wosh::xtended::Metronome)
	WOSH_CLASS_ABSTRACT(false)


	public:
		/**
		 * @brief   Default constructor. Init vars.
		 */
		Metronome();
		/**
		 * @brief  Empty destructor.
		 */
		virtual ~Metronome();


	public:
		WRESULT startMetronome( unsigned long synch_timeout = LIMIT_ULONG_MAX );
		WRESULT stopMetronome( unsigned long synch_timeout = LIMIT_ULONG_MAX );

		WRESULT setListener( IMetronomeListener* listener );

/** @name Getters
 * @{
 ******************************************************************************/
	public:
		bool isDisabled() const;

		unsigned long getPeriod() const;

//@}
/** @name Setters
 * @{
 ******************************************************************************/
	public:
		void setDisabled( bool disabled = true );

		void setPeriod( unsigned long millisec );

		using Thread::setOwnerObject;

//@}
/** @name Internal methods
 * @{
 ******************************************************************************/
	protected:
		virtual bool initializingThread();

		virtual void runThread();

//@}
	protected:
		IMetronomeListener* listener;

		bool disabled;
		MutexRW configMux;

		unsigned long period;

}; // class def




class IMetronomeListener {
	public:
		virtual void tickEvent( int64 time, Metronome* source ) = 0;

	public:
		virtual ~IMetronomeListener() { }

}; // class def




 }; // namespace xtended
}; // namespace wosh

#endif //__WOSH_Xtended_Metronome_H__
